package com.heartware.sh.blackhole.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.heartware.sh.blackhole.common.FragmentFactory;
import com.heartware.sh.blackhole.entity.FragmentInfo;
import com.heartware.sh.blackhole.ui.fragment.NullFragment;
import com.heartware.sh.blackhole.ui.fragment.base.BaseNullFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/3/22 0022.
 */

public class NineTabAdapter extends FragmentStatePagerAdapter {

    private List<FragmentInfo> fragmentInfos = new ArrayList<>();

    public NineTabAdapter(FragmentManager fm) {
        super(fm);

        init();
    }

    public void init(){

        for (int i=0 ; i<4; i++){
            fragmentInfos.add(FragmentFactory.createFragmentInfo(i));
        }

    }

    @Override
    public BaseNullFragment getItem(int position) {
        return FragmentFactory.createFragment(position, fragmentInfos.get(position));
//        BaseNullFragment bnf= null;
//        try {
//            bnf = (BaseNullFragment) fragmentInfos.get(position).getFragment().newInstance();
//        } catch (InstantiationException e) {
//            e.printStackTrace();
//        } catch (IllegalAccessException e) {
//            e.printStackTrace();
//        }
//        return bnf;
    }

    @Override
    public int getCount() {
        return fragmentInfos.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {

        return fragmentInfos.get(position).getTitle();
    }
}
